package Chapter4;

import java.util.Scanner;
//91页程序4.6
class GeneralFunction{
    public static int addUp(int x,int y){  //定义了静态方法，使得主程序可以不创建对象，直接通过类名.方法名访问方法的程序代码
        return x+y;
    }
}
public class UseGeneral {
    public static void main(String[] args) {
        Scanner scanner_a = new Scanner(System.in);
        System.out.println("请输入运算a的值：");
        try {
            int scan_a = scanner_a.nextInt();
            System.out.println("请输入运算b的值：");
            int scan_b = scanner_a.nextInt();
            int c=GeneralFunction.addUp(scan_a,scan_b);
            System.out.println("在加法运算下，"+scan_a+"和"+scan_b+"输出结果为："+c);
        }catch (Exception e){
            System.out.println("输入的值错误！");
            System.exit(0);
        }
    }
}
